<cfif fileexists( expandpath('../../xml/webservices.xml') )>
	<cffile action="read" file="#expandpath('../../xml/webservices.xml')#" variable="appxml"/>
	<cfscript>
		thexml = appxml;
		// xml query to get array of each individual rows
		base 	= "/application/tables/table";
		records = xmlsearch(thexml, base);
		session.qtables = QueryNew("id,object,pk,dbtype,dsn","varchar,varchar,varchar,varchar,varchar");	
		// Loop thru each set of countyproject in case there were several
		for(i = 1; i lte arraylen(records); i = i + 1)
		{			
			// grab current countyproject
			record			= records[i];
			// get values
			QueryAddRow(session.qtables);
			QuerySetCell( session.qtables, "id"				, getXmlValue(thexml,  base, 'id', i) );
			QuerySetCell( session.qtables, "object"			, getXmlValue(thexml,  base, 'object', i) );
			QuerySetCell( session.qtables, "pk"				, getXmlValue(thexml,  base, 'pk', i) );
			QuerySetCell( session.qtables, "dbtype"			, getXmlValue(thexml,  base, 'dbtype', i) );
		}
	</cfscript>
</cfif>
<cfif fileexists( expandpath('../../xml/datasource.xml') )>
	<cffile action="read" file="#expandpath('../../xml/datasource.xml')#" variable="appxml"/>
	<cfscript>
		thexml = appxml;
		// xml query to get array of each individual rows
		base 	= "/datasource";
		records = xmlsearch(thexml, base);
		session.dsn = getXmlValue(thexml,  base, 'name', 1);	
	</cfscript>
</cfif>

<cfif fileexists( expandpath('../../Application.cfc') )>
	<cffile action="read" file="#expandpath('../../Application.cfc')#" variable="appcfc"/>
	<cfset results = rereplace(appcfc,"(.*?)(this.name = "")(.*?)("".*)","\3","ONE") />
	<cfset session.appname = results />
</cfif>

<cfif fileexists( expandpath('../../xml/transfer.xml') )>
	<cffile action="read" file="#expandpath('../../xml/transfer.xml')#" variable="appxml"/>
	<cfscript>
		thexml = appxml;
		// xml query to get array of each individual rows
		base 	= "/transfer/objectDefinitions/package";
		records = xmlsearch(thexml, base);
		session.packagename = records[1].xmlattributes.name;
	</cfscript>
</cfif>

<cffunction name="getXmlValue" access="public" output="false" returntype="string">
	<cfargument name="xml" required="true" type="string"/>
	<cfargument name="xpath" required="true" type="string"/>
	<cfargument name="field" required="true" type="string"/>
	<cfargument name="position" required="false" type="numeric" default="1">
	<cfset var valuearray = "" />
	<cfset var value = "" />
	<cfscript>
		// use xmlsearch to grab that element
		valuearray=xmlsearch(arguments.xml,"#arguments.xpath#[#arguments.position#]/#arguments.field#");
		// get the field, which is the first elemnt of the array
		try
		{
			value=valuearray[1].xmltext;
		}
		catch(Any e)
		{
			value="";
		}
	</cfscript>
	<cfreturn value />
</cffunction>
